/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package bean;

import ejb.Calendarejb;
import ejb.Loginejb;
import entity.Event;
import java.io.Serializable;
import java.util.Collection;
import java.util.Iterator;
import javax.annotation.PostConstruct;
import javax.faces.view.ViewScoped;
import javax.inject.Inject;
import javax.inject.Named;
import org.primefaces.model.DefaultScheduleEvent;
import org.primefaces.model.DefaultScheduleModel;
import org.primefaces.model.ScheduleModel;

/**
 *
 * @author user
 */
@Named

@ViewScoped

public class Calendarbean implements Serializable {

    @Inject
    Calendarejb calejb;

    @Inject
    Loginejb logejb;

    private ScheduleModel eventModel;

    private Event event;
   
    private Collection<Event> eventCollection;

    @PostConstruct
    public void init() {
        System.out.println("Calendar Initialization");
        eventModel = new DefaultScheduleModel();
        eventCollection = calejb.getEventsinCalendar(logejb.loggedUser()).getEventCollection();
        Iterator itr = eventCollection.iterator();
        event = (Event) itr.next();
        while (itr.hasNext()) {
            System.out.println("load event: " + event.getName());
            eventModel.addEvent(new DefaultScheduleEvent(event.getName(), event.getStartDateTime(), event.getEndDateTime()));
            event = (Event) itr.next();
        }
        if (event != null) {
            eventModel.addEvent(new DefaultScheduleEvent(event.getName(), event.getStartDateTime(), event.getEndDateTime()));
            System.out.println("load event: " + event.getName());
        }

        //eventModel.addEvent(new DefaultScheduleEvent("prova", Calendar.getInstance().getTime(), Calendar.getInstance().getTime()));
        //eventModel.addEvent(new DefaultScheduleEvent(calejb.getEvent().getName(), calejb.getEvent().getDate(), calejb.getEvent().getDate()));
    }

    public Event getEvent() {
        return event;
    }

    public void setEvent(Event event) {
        this.event = event;
    }

    public ScheduleModel getEventModel() {
        return eventModel;
    }

    public void setEventModel(ScheduleModel eventModel) {
        this.eventModel = eventModel;
    }
    

}

